package com.ynu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.ynu.bean.entity.Category;
import com.ynu.bean.vo.CategoryVO;
import com.ynu.converter.CategoryConverter;
import com.ynu.mapper.CategoryMapper;
import com.ynu.service.CategoryService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  模块名称：
 *  模块类型：
 *  编码人：迟宽席
 *  创建时间：2023/3/1
 *  联系电话：18388068273
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    @Resource
    private CategoryConverter categoryConverter;

    @Override
    public List<CategoryVO> getTopCategory(Integer size) {
        Page<Category> page = PageHelper.startPage(1, size);
        //可用
        categoryMapper.selectTopCategory(1);
        List<Category> categoryList = page.getResult();

        List<CategoryVO> categoryVOList = categoryConverter.categoryList2CategoryVOList(categoryList);
        return categoryVOList;
    }

    @Override
    public List<CategoryVO> getCategoryByPid(Long pid, Integer pageNum, Integer pageSize) {
        Page<Category> page = PageHelper.startPage(pageNum, pageSize);
        //可用
        categoryMapper.selectCategoryByPid(pid, 1);
        List<Category> categoryList = page.getResult();

        List<CategoryVO> categoryVOList = categoryConverter.categoryList2CategoryVOList(categoryList);
        return categoryVOList;
    }
}
